<?php



function connettiDb()
{
	require'config.php';
	//var_dump($db);
	
mysql_connect($db['host'],$db['userdb'],$db['password']) 
or die('impossibile collegarsi al server');

mysql_select_db($db['nomeDB'])
or die('impossibile collegarsi al database');


}

function getPage($id, $lang = 'it')
{
connettiDb();

	$sql_it = "SELECT *id,section,
			   sub_section,status,
			   title_$lang AS title,
			   content_$lang AS content
	           FROM pages
	           WHERE id = $id AND status = 1";
	
	
			$result = mysql_query($sql);
			return $result;	
}
function getAllPages($lang = 'it')
{
	connettiDb();
	$sql ="SELECT *id,section,
			   sub_section,status,
			   title_$lang AS title,
			   content_$lang AS content
	           FROM pages
	           WHERE status = 1 
	           ORDER BY title";
	
			$result = mysql_query($sql);
			return $result;	
	
}
function getAllPagesBySection($section,$subSection,$lang = 'it')
{
	connettiDb();
	$sql ="SELECT *id,section,
			   sub_section,status,
			   title_$lang AS title,
			   content_$lang AS content
	           FROM pages
	           WHERE status = 1 AND section = $section 
	           AND sub_section = $subSection
	           ORDER BY sub_section,title";
	
			$result = mysql_query($sql);
			return $result;	
	
}
function isCorrectSection ($request)
{
	require_once 'config.php';
	
	return isset ($section [$request]);
}